package com.cddx.logistics.controller;

import com.cddx.logistics.domain.dto.SysDictItemQueryDTO;
import com.cddx.logistics.domain.pojo.SysDictItem;
import com.cddx.logistics.domain.vo.SysDictItemVO;
import com.cddx.logistics.service.SysDictItemService;
import com.cddx.logistics.util.model.R;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/sysDictItem")
@Api(tags = "字典项管理控制器")
public class SysDictItemController {

    @Resource
    private SysDictItemService sysDictItemService;
    @GetMapping("/queryPage")
    @ApiModelProperty("分页查询字典项")
    public R  queryPage(SysDictItemQueryDTO sysDictItemQueryDTO) {
        PageInfo<SysDictItemVO> pageInfo = sysDictItemService.queryPage(sysDictItemQueryDTO);
        return R.ok(pageInfo);
    }

    /**
     * 删除字典
     */
    @GetMapping("/delete")
    @ApiModelProperty("删除字典项")
    public R  delete(Integer id){
        return sysDictItemService.delete(id)?R.ok("删除成功"):R.error("删除失败");
    }

    /**
     * 添加字典
     */
    @PostMapping("/add")
    @ApiModelProperty("添加字典项")
    public R  add(SysDictItem sysDictItem){
        return sysDictItemService.add(sysDictItem)?R.ok("添加成功"):R.error("添加失败");
    }

    /**
     * 修改字典
     */
    @PostMapping("/update")
    @ApiModelProperty("修改字典项")
    public R  update(SysDictItem sysDictItem){
        return sysDictItemService.update(sysDictItem)?R.ok("修改成功"):R.error("修改失败");
    }



}
